package com.mgface.framework.springcloud;

import com.mgface.framework.springcloud.annotation.ExcludeFromComponentScan;
import com.mgface.framework.springcloud.conf.TestConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.web.client.RestTemplate;

/**
 * @author wanyuxiang
 * @version 1.0
 * @project ms-ribbon
 * @create 2017-04-10 17:32
 * @desc 做负载均衡的组件
 **/
@SpringBootApplication
@EnableDiscoveryClient
//ms-provider-user这个称为VIP(虚拟IP)->是ms-provider-user项目application.yml属性spring.application.name的设置
//-------------------------------------------------------------------------------------------------------
//以下配置ms-provider-user这个VIP使用TestConfiguration配置的随机策略，其他的VIP还是使用默认的轮询策略
//如果不使用@ComponentScan进行注解排除，只要TestConfiguration被@ComponentScan扫描出来，那么它的策略就会应用到所有的VIP
@RibbonClient(name = "ms-provider-user",configuration=TestConfiguration.class)
@ComponentScan(excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = ExcludeFromComponentScan.class)})
public class CustomizingRibbonApplication {
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    public static void main(String[] args) {
        SpringApplication.run(CustomizingRibbonApplication.class,args);
    }
}
